﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using Hotel.Classes.Helper;
using Hotel.Models.Entity;

namespace Hotel.Models.DataAccess
{
    public class DAGroupStaff
    {
        public static List<GroupStaff> GetListGroupStaff(int gsID)
        {
            DataTable dt;
            List<GroupStaff> list = new List<GroupStaff>();
            using (DBManager dbManager = new DBManager("stp_Get_GroupStaff"))
            {
                dbManager.Add("p_PK_GroupStaffID", gsID);
                dbManager.Add("IsDelete", 0);
                dt = dbManager.GetDatatable();
            }
            foreach (DataRow dr in dt.Rows)
            {
                GroupStaff gs = new GroupStaff();
                gs.PkGroupStaffId = DataHelper.GetInt(dr, "PK_GroupStaffID");
                gs.Name = DataHelper.Get(dr, "Name");
                gs.Note = DataHelper.Get(dr, "Note");
                gs.Authorities = DataHelper.GetInt(dr, "Authorities");
                list.Add(gs);
            }
            return list;
        }

        public static bool DeleteGroupStaff(int gsID)
        {
            using (DBManager dbManager = new DBManager("stp_Get_GroupStaff"))
            {
                try
                {
                    dbManager.Add("p_PK_GroupStaffID", gsID);
                    dbManager.Add("IsDelete", 0);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
                
            }
        }

        public static bool SaveGroupStaff(GroupStaff gs, bool isUpdate)
        {
            using (DBManager dbManager = new DBManager("stp_Create_GroupStaff"))
            {
                try
                {
                    dbManager.Add("p_PK_GroupStaffID", gs.PkGroupStaffId);
                    dbManager.Add("p_Name", gs.Name);
                    dbManager.Add("p_Note", gs.Note);
                    dbManager.Add("p_Authorities", gs.Authorities);
                    dbManager.Add("IsUpdate", isUpdate);
                    dbManager.ExecuteNonQuery();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
    }
}